
//
//  DeviceDetailInfoViewController.m
//  CityFire
//
//  Created by Liuyz on 2017/8/23.
//  Copyright © 2017年 刘养柱. All rights reserved.
//

#import "DeviceDetailInfoViewController.h"
#import "DeviceDetailInfoTableViewCell.h"
#import "UITextView+Placeholder.h"
#import "MonitorViewModel.h"

@interface DeviceDetailInfoViewController () <UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, weak) IBOutlet UITableView *tableView;
@property (nonatomic, weak) IBOutlet UITextView *markTextView;
@property (nonatomic, weak) IBOutlet UIButton   *checkBtn;
@property (nonatomic, weak) IBOutlet UIButton   *updateBtn;
@property (weak, nonatomic) IBOutlet UILabel *markLbl;
@property (nonatomic, strong) MonitorViewModel *monitorViewModel;

@end

@implementation DeviceDetailInfoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self configUI];
}

- (void)configUI
{
    if (self.isShowMisinformationInfo) {
        self.checkBtn.hidden = NO;
        self.markLbl.hidden = NO;
        self.markTextView.hidden = NO;
    } else{
        self.checkBtn.hidden = YES;
        self.markLbl.hidden = YES;
        self.markTextView.hidden = YES;
    }
    self.markTextView.placeholder = @"填写处理结果";
    self.updateBtn.layer.cornerRadius = self.updateBtn.frame.size.height / 2;
    self.updateBtn.layer.masksToBounds = YES;
    self.checkBtn.selected = [self.isMisinformation isEqualToString:@"1"]?YES:NO;
}

//- (void)bindRAC
//{
//    [RACObserve(self.monitorViewModel, requestError) subscribeNext:^(NSError *requestError) {
//        
//    }];
//}
    
- (IBAction)checkBtnClicked:(UIButton *)sender
{
    sender.selected = !sender.selected;
}
    
- (IBAction)updateBtnClicked:(id)sender
{
    if (!self.markTextView.text.length) {
        [SVProgressHUD showInfoWithStatus:@"请输入处理结果"];
        return;
    }
    
    [self.monitorViewModel getWarningDeal:@{@"record_usr_log" : self.markTextView.text, @"misinformation" : self.checkBtn.selected ? @(0) : @(1)}];
}
    
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return self.itemsArray.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [self.itemsArray[section] count];
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 10;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 44;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    DeviceDetailInfoTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"DeviceDetailInfoTableViewCell"];
    cell.textLabel.text = self.itemsArray[indexPath.section][indexPath.row];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    return cell;
}
    
- (MonitorViewModel *)monitorViewModel
{
    if (_monitorViewModel == nil) {
        _monitorViewModel = [[MonitorViewModel alloc] init];
    }
    
    return _monitorViewModel;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
